$(function () {
    validateData();
    //页面加载完成获取第一页数据
    getGradeConfigList(1);
});
/**
 * 获取角色列表页面
 * @param pageNo 当前页码
 */
function getGradeConfigList(pageNo) {
    var params = "";
    var obj = {
        url: baseloaction + '/admin/user/cus/ajaxCusUserGradeConfigList',//请求URL
        contextId: 'gradeconfig-list-context',//响应内容页面设置内容ID
        params: params,//请求参数
        pageNo: pageNo,//页码
        pageCall: getGradeConfigList, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
        selectAllId: 'select-all-role', //全选框ID
        callback: function () {//数据加载完成回调

        }
    };
    ajaxGetListData(obj)
}

/**
 * 新建等级和等级编辑按钮弹窗
 */
$(function () {
    $("body").on('click', "#create-userGrade,.grade-config-box", function () {
        var _this = $(this);
        var id = _this.data('id');
        parent.layer.open({
            area: ['40%', '75%'],
            btn: ['保存', '关闭'],
            content: baseloaction + "/admin/user/cus/saveCusUserGradeConfig?gradeConfigId=" + id,
            shade: [0.3, '#000'],
            shadeClose: false,
            title: '填写基本信息',
            type: 2,
            yes: function (index) {
                var body = parent.layer.getChildFrame('body', index);
                var gradeName = body.find('#gradeName').val();
                var gradeTitle = body.find('#gradeTitle').val();
                var experience = body.find('#experience').val();
                $.ajax({
                    url: baseloaction + '/admin/user/cus/ajaxSaveCusUserGradeConfig',
                    type: "post",
                    data: {"id": id, "gradeName": gradeName, "gradeTitle": gradeTitle, "experience": experience},
                    dataType: "json",
                    success: function (result) {
                        if (result.success == true) {
                            icModale(0, result.message);
                            parent.layer.close(index);
                            var parents = _this.parents('tr');
                           if(result.entity.id==1){
                               window.location.href=baseloaction+"/admin/user/cus/gradeConfigList"
                           }
                            if (!id) {
                                var html = '<tr>' +
                                    '<td class="text-center" >' + gradeName + '</td>' +
                                    '<td class="text-center" >' + gradeTitle + '</td>' +
                                    '<td class="text-center" >' + experience + '</td>' +
                                    '<td class="text-center" >' +
                                    '<a href="javascript:void(0)" data-id="' + result.entity + '" class="c-master fs14 ml5 grade-config-box" data-toggle="tooltip" data-placement="bottom" data-original-title="编辑"><i class="fa fa-edit"></i></a>' +
                                    '</td></tr>';
                                $('#grade-table').append(html);
                            } else {
                                parents.find('td:eq(0)').html(gradeName).next().html(gradeTitle).next().html(experience);
                            }
                        } else {
                            icModale(0, result.message);
                        }
                    },
                    error: function (error) {
                        icModale(0, "系统繁忙，请稍后重试");
                    }
                });
             /*   parent.layer.close(index);*/
            }
        });
    });
});
